package org.chen.common.aspect;

import org.apache.shardingsphere.api.hint.HintManager;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.chen.common.annotation.MasterRoute;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class MasterRouteAspect {

    @Around("@annotation(masterRoute)")
    public Object routeMaster(ProceedingJoinPoint joinPoint, MasterRoute masterRoute) throws Throwable {
        try (HintManager hintManager = HintManager.getInstance()) {
            hintManager.setMasterRouteOnly();
            return joinPoint.proceed();
        }
    }
}
